<?php
$this->pageTitle = 'Detail osoby';
?>
<div class="viewForm">
	<h3>Detail osoby
	<?php if (isset($userPermissions['person']['edit'])) {
		echo $this->Html->link(__('Uprav', true), array('controller' => 'person', 'action' => 'edit', $person['Person']['id']), array('class' => 'edit'));
	}?>
	</h3>
	<dl>
		<!--
		<?php if ($person['Person']['titles_before']): ?>
		<dt>Tituly pred menom:</dt>
		<dd><?php echo htmlspecialchars($person['Person']['titles_before']); ?></dd>
		<?php endif; ?>
		-->
		<dt>Meno:</dt>
		<dd><?php echo htmlspecialchars($person['Person']['name']); ?></dd>

		<dt>Priezvisko:</dt>
		<dd><?php echo htmlspecialchars($person['Person']['surname']); ?></dd>

		<!--
		<?php if ($person['Person']['titles_after']): ?>
			<dt>Tituly za menom:</dt>
			<dd><?php echo htmlspecialchars($person['Person']['titles_after']); ?></dd>
		<?php endif; ?>
		-->

		<?php if ($person['Person']['birthday_check']): ?>
			<dt>Dátum narodenia:</dt>
			<dd><?php echo $person['Person']['birthday']; ?></dd>
		<?php endif; ?>

		<?php if ($person['Person']['fk_parent_person_id']): ?>
			<dt>Nadradená osoba vo firemnej štruktúre:</dt>
			<dd><?php echo $this->Html->link(htmlspecialchars($person['Parent']['full_name']), array('action' => 'view', $person['Parent']['id'])); ?></dd>
		<?php endif; ?>

		<dt>Typ osoby:</dt>
		<dd><?php echo $person['PersonType']['title']; ?></dd>

		<?php if ($person['Person']['email']): ?>
		<dt>E-mail:</dt>
		<dd><?php echo $person['Person']['email']; ?></dd>
		<?php endif; ?>

		<?php if ($person['Person']['phone']): ?>
		<dt>Telefón:</dt>
		<dd><?php echo $person['Person']['phone']; ?></dd>
		<?php endif; ?>

		<?php if ($showDetailData === TRUE): ?>
		<?php
			$personModel = new Person($person['Person']['id']);
			$bitches = $personModel->getBitches();
			if ($bitches): ?>
			<dt>Osoby, ktoré získajú províziu (vrátane mňa):</dt>
			<dd>
				<div class="listing">
					<table class="list">
						<thead>
							<tr>
								<th>Typ osoby</th>
								<th>Osoba</th>
								<th class="col50" colspan="3"><?php echo 'Provízia (%)'; ?></th>
							</tr>
						</thead>
						<tbody>
							<?php foreach ($bitches as $bitch): ?>
							<tr>
								<td><?php echo $this->Html->link(htmlspecialchars($bitch['PersonType']['title']), array('controller' => 'person_type', 'action' => 'view', $bitch['PersonType']['id'])); ?></td>
								<td><?php echo $this->Html->link(htmlspecialchars($bitch['Person']['full_name']), array('controller' => 'person', 'action' => 'view', $bitch['Person']['id'])); ?></td>
								<td class="number">
									<?php 
										$commission = $bitch['Commission']['commission_0_tipsters'];
										if (in_array($commission, array(0, 100))) {
											echo '-';
										} else {
											echo $commission;
										}
									?>
								</td>
								<td class="number">
									<?php 
										$commission = $bitch['Commission']['commission_1_tipster'];
										if (in_array($commission, array(0, 100))) {
											echo '-';
										} else {
											echo $commission;
										}
									?>
								</td>
								<td class="number">
									<?php 
										$commission = $bitch['Commission']['commission_2_tipsters'];
										if (in_array($commission, array(0, 100))) {
											echo '-';
										} else {
											echo $commission;
										}
									?>
								</td>
							</tr>
							<?php endforeach; ?>		
						</tbody>
					</table>
				</div>
			</dd>
			<?php endif; ?>
		<?php endif; ?>
	</dl>
	<div class="clear"></div>
</div>

<?php if ($showDetailData === TRUE): ?>
	<?php if ($offers): ?>
	<div class="listing">
		<h3>Zoznam ponúk</h3>
		<table class="list">
			<thead>
				<tr>
					<th class="identifier"><?php echo 'ID'; ?></th>
					<th><?php echo 'Popis'; ?></th>
					<th class="col100"><?php echo 'Klient'; ?></th>
					<th class="col100"><?php echo 'Tiper'; ?></th>
					<th class="col100"><?php echo 'Maklér'; ?></th>
					<th class="action"><?php echo 'Akcie'; ?></th>
				</tr>
			</thead>
			<tbody>
				<?php
				foreach ($offers as $market):
				?>
				<tr>
					<td class="number">
						<?php echo $market['Market']['id']; ?>
					</td>
					<td>
						<?php echo $market['Market']['html_description']; ?>
					</td>
					<td>
						<?php echo $this->Html->link(htmlspecialchars($market['Client']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Client']['id'])); ?>
					</td>
					<td>
						<?php echo $this->Html->link(htmlspecialchars($market['Tipster']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Tipster']['id'])); ?>
					</td>
					<td>
						<?php echo $this->Html->link(htmlspecialchars($market['Broker']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Broker']['id'])); ?>
					</td>
					<td>
						<?php
							if (isset($userPermissions['market']['view'])) {
								echo $this->Html->link(__('View', true), array('controller' => 'market', 'action' => 'view', $market['Market']['id']), array('class' => 'show'));
							}
						?>
						<?php
							if (isset($userPermissions['market']['edit'])) {
								echo $this->Html->link(__('Uprav', true), array('controller' => 'market', 'action' => 'edit', $market['Market']['id']), array('class' => 'edit'));
							}
						?>
						<?php
							if (isset($userPermissions['market']['delete'])) {
								echo $this->Html->link(__('Delete', true), array('controller' => 'market', 'action' => 'delete', $market['Market']['id']), array('class' => 'delete'), __('Ste si istý, že chcete odstrániť záznam?', true));
							}
						?>
					</td>
				</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
	</div>
	<?php endif; ?>

	<?php if ($demands): ?>
	<div class="listing">
		<h3>Zoznam dopytov</h3>
		<table class="list">
			<thead>
				<tr>
					<th class="identifier"><?php echo 'ID'; ?></th>
					<th><?php echo 'Popis'; ?></th>
					<th class="col100"><?php echo 'Klient'; ?></th>
					<th class="col100"><?php echo 'Tiper'; ?></th>
					<th class="col100"><?php echo 'Maklér'; ?></th>
					<th class="action"><?php echo 'Akcie'; ?></th>
				</tr>
			</thead>
			<tbody>
				<?php
				foreach ($demands as $market):
				?>
				<tr>
					<td class="number">
						<?php echo $market['Market']['id']; ?>
					</td>
					<td>
						<?php echo $market['Market']['html_description']; ?>
					</td>
					<td>
						<?php echo $this->Html->link(htmlspecialchars($market['Client']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Client']['id'])); ?>
					</td>
					<td>
						<?php echo $this->Html->link(htmlspecialchars($market['Tipster']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Tipster']['id'])); ?>
					</td>
					<td>
						<?php echo $this->Html->link(htmlspecialchars($market['Broker']['full_name']), array('controller' => 'person', 'action' => 'view', $market['Broker']['id'])); ?>
					</td>
					<td>
						<?php
							if (isset($userPermissions['market']['view'])) {
								echo $this->Html->link(__('View', true), array('controller' => 'market', 'action' => 'view', $market['Market']['id']), array('class' => 'show'));
							}
						?>
						<?php
							if (isset($userPermissions['market']['edit'])) {
								echo $this->Html->link(__('Uprav', true), array('controller' => 'market', 'action' => 'edit', $market['Market']['id']), array('class' => 'edit'));
							}
						?>
						<?php
							if (isset($userPermissions['market']['delete'])) {
								echo $this->Html->link(__('Delete', true), array('controller' => 'market', 'action' => 'delete', $market['Market']['id']), array('class' => 'delete'), __('Ste si istý, že chcete odstrániť záznam?', true));
							}
						?>
					</td>
				</tr>
				<?php endforeach; ?>
			</tbody>
		</table>
	</div>
	<?php endif; ?>

	<?php if ($commissions): ?>
	<div class="listing">
		<h3>Zoznam depozitov</h3>
		<table class="list">
			<thead>
				<tr>
					<th class="identifier"><?php echo 'ID'; ?></th>
					<th class=""><?php echo 'Obrat'; ?></th>
					<th class="col100"><?php echo 'Typ osoby'; ?></th>
					<th class="col20"><?php echo '%'; ?></th>
					<th class="col50"><?php echo 'Hodnota'; ?></th>
					<?php if (isset($userPermissions['commission']['view']) || isset($userPermissions['commission']['edit']) || isset($userPermissions['commission']['delete'])): ?>
					<th class="action"><?php echo 'Akcie'; ?></th>
					<?php endif; ?>
				</tr>
			</thead>
			<tbody>
				<?php
				foreach ($commissions as $commission):
				?>
				<tr>
					<td class="number">
						<?php echo $commission['Commission']['id']; ?>
					</td>
					<td>
						<?php echo $this->Html->link('Detail', array('controller' => 'transfer', 'action' => 'view', $commission['Transfer']['id'])); ?>
					</td>
					<td>
						<?php echo $this->Html->link(htmlspecialchars($commission['PersonType']['title']), array('controller' => 'person', 'action' => 'view', $commission['PersonType']['id'])); ?>
					</td>
					<td class="number">
						<?php echo $commission['Commission']['percentage']; ?>
					</td>
					<td class="number">
						<?php echo $commission['Commission']['value']; ?>
					</td>
					<?php if (isset($userPermissions['commission']['view']) || isset($userPermissions['commission']['edit']) || isset($userPermissions['commission']['delete'])): ?>
					<td>
						<?php
							if (isset($userPermissions['commission']['view'])) {
								echo $this->Html->link(__('View', true), array('action' => 'view', $commission['Commission']['id']), array('class' => 'show'));
							}
						?>
						<?php
							if (isset($userPermissions['commission']['edit'])) {
								echo $this->Html->link(__('Uprav', true), array('action' => 'edit', $commission['Commission']['id']), array('class' => 'edit'));
							}
						?>
						<?php
							if (isset($userPermissions['commission']['delete'])) {
								echo $this->Html->link(__('Delete', true), array('action' => 'delete', $commission['Commission']['id']), array('class' => 'delete'), __('Ste si istý, že chcete odstrániť záznam?', true));
							}
						?>
					</td>
					<?php endif; ?>
				</tr>
				<?php endforeach; ?>
			</tbody>
		</table>

		<?php if ($this->Paginator->hasPage(2)): ?>
			<div class="pager">
				<?php echo $this->Paginator->prev('<< '.__('predchádzajúca', true), array(), null, array('class'=>'disabled')); ?>
				<?php echo $this->Paginator->numbers(); ?>
				<?php echo $this->Paginator->next(__('ďalšia', true).' >>', array(), null, array('class' => 'disabled')); ?>
			</div>
		<?php endif; ?>
	</div>
	<?php endif; ?>
<?php endif; ?>